﻿using System;
using System.Collections.Generic;
using System.Text;

namespace LanhuFx.Services
{
    public class PagerCondition<T>
    {
        public PagerCondition()
        {
            PageSize = 10;
        }

        private int _pageIndex;
        private int _pageSize;
        private int _dataCount;

        /// <summary>
        /// 当前页
        /// </summary>
        public int PageIndex
        {
            get
            {
                if (_pageIndex <= 1)
                    return 1;

                return _pageIndex;
            }
            set { _pageIndex = value; }
        }

        /// <summary>
        /// 每页显示数量
        /// </summary>
        public int PageSize
        {
            get
            {
                if (_pageSize >= 1000)
                    return 1000;

                if (_pageSize <= 1)
                    return 1;

                return _pageSize;
            }
            set { _pageSize = value; }
        }

        /// <summary>
        /// 数据总行数（非分页）
        /// </summary>
        public int DataCount
        {
            get
            {
                return _dataCount;
            }
        }

        public void SetDataCount(int arg_dataCount)
        {
            this._dataCount = arg_dataCount;
        }

        /// <summary>
        /// 数据查询起始行数
        /// </summary>
        public int Start
        {
            get
            {
                return (PageIndex - 1) * PageSize;
            }
        }

        /// <summary>
        /// 总页数
        /// </summary>
        public int PageCount
        {
            get
            {
                if (DataCount % PageSize != 0)
                {
                    return (DataCount / PageSize) + 1;
                }
                else
                {
                    return DataCount / PageSize;
                }
            }
        }

        /// <summary>
        /// 自定义搜索条件
        /// </summary>
        public T CustomerSearch { get; set; }
    }
}
